//
//  Pac_GetLocalCfView.m
//  TY-C
//
//  Created by xyyl on 2024/5/17.
//

#import "Pac_GetLocalCfView.h"

@implementation Pac_GetLocalCfView


- (instancetype)initWithFrame:(CGRect)frame {
    if (self == [super initWithFrame:frame]) {
        self.frame = CGRectMake(0, 0, ZYQWIDTH, [UIApplication sharedApplication].keyWindow.frame.size.height);
        
        [[UIApplication sharedApplication].keyWindow addSubview:self];
        
        self.clipsToBounds = YES;
        self.layer.cornerRadius = 10 * IPADSCALE;
        [self initViews];
        [self initFrames];
        self.backgroundColor = RGBAColor(0, 0, 0, 0.2);
    }
    return self;
}

- (void)initFrames {
    [_whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.height.equalTo(@(265*IPADSCALE));
        make.width.equalTo(@(290 * IPADSCALE));
    }];
    _whiteView.backgroundColor = [UIColor whiteColor];
    
    _whiteView.clipsToBounds = YES;
    _whiteView.layer.cornerRadius = 10 * IPADSCALE;
    
    [_tipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(27*IPADSCALE));
        make.top.left.right.equalTo(_whiteView);
    }];
    _tipsLab.text = @"     读取主机当前处方";
    _tipsLab.font = ZYQFONT(18);
    _tipsLab.textColor = RGBColor(102, 102, 102);
    _tipsLab.backgroundColor = RGBColor(250, 250, 250);
    
    [_sjjrBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(85*IPADSCALE));
        make.height.equalTo(@(22*IPADSCALE));
        make.top.equalTo(_tipsLab.mas_bottom).offset(21*IPADSCALE);
        make.right.equalTo(_whiteView.mas_centerX);
    }];
    [_sjjrBtn setTitle:@"神经肌肉电刺激" forState:0];
    [_sjjrBtn setBackgroundColor:RGBColor(13, 157, 219)];
    [_sjjrBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [_sjjrBtn setTitleColor:RGBColor(13, 157, 219) forState:0];
    _sjjrBtn.selected = YES;
    _sjjrBtn.layer.borderWidth = 2;
    _sjjrBtn.layer.borderColor =RGBColor(13, 157, 219).CGColor;
    
    [_cfBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(85*IPADSCALE));
        make.height.equalTo(@(22*IPADSCALE));
        make.top.equalTo(_tipsLab.mas_bottom).offset(21*IPADSCALE);
        make.left.equalTo(_whiteView.mas_centerX);
    }];
    [_cfBtn setTitle:@"触发电刺激" forState:0];
    [_cfBtn setBackgroundColor:[UIColor whiteColor]];
    [_cfBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [_cfBtn setTitleColor:RGBColor(13, 157, 219) forState:0];
    _cfBtn.selected = 0;
    _cfBtn.layer.borderWidth = 2;
    _cfBtn.layer.borderColor =RGBColor(13, 157, 219).CGColor;
    
    [_cfBtn addTarget:self action:@selector(cfOrSjjrbtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [_sjjrBtn addTarget:self action:@selector(cfOrSjjrbtnAction:) forControlEvents:UIControlEventTouchUpInside];
    

    [_zlsjView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(111*IPADSCALE));
        make.height.equalTo(@(22*IPADSCALE));
        make.right.equalTo(_whiteView.mas_centerX).offset(-10*IPADSCALE);
        make.top.equalTo(_cfBtn.mas_bottom).offset((20*IPADSCALE));
    }];
    _zlsjView.nameLab.text = @"治疗时间";
    _zlsjView.mesLab.text = @"55";
    _zlsjView.dwLab.text = @" min";

    
    [_cxsjView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.right.equalTo(_zlsjView);
        make.top.equalTo(_zlsjView.mas_bottom).offset((7*IPADSCALE));
    }];
    _cxsjView.nameLab.text = @"持续时间";
    _cxsjView.mesLab.text = @"15";
    
    [_jgsjView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.right.equalTo(_zlsjView);
        make.top.equalTo(_cxsjView.mas_bottom).offset((7*IPADSCALE));
    }];
    _jgsjView.nameLab.text = @"间隔时间";
    _jgsjView.mesLab.text = @"5";
    
    [_sssjView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.right.equalTo(_zlsjView);
        make.top.equalTo(_jgsjView.mas_bottom).offset((7*IPADSCALE));
    }];
    _sssjView.nameLab.text = @"上升时间";
    _sssjView.mesLab.text = @"2";
    
    [_xjsjView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.top.equalTo(_zlsjView);
        make.left.equalTo(_whiteView.mas_centerX).offset(10*IPADSCALE);
    }];
    _xjsjView.nameLab.text = @"下降时间";
    _xjsjView.mesLab.text = @"2";
    
    [_ycsjView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.left.equalTo(_xjsjView);
        make.top.equalTo(_cxsjView);
    }];
    _ycsjView.nameLab.text = @"延迟时间";
    _ycsjView.mesLab.text = @"-";
    _ycsjView.dwLab.text = @"";
    
    [_plView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.left.equalTo(_xjsjView);
        make.top.equalTo(_jgsjView);
    }];
    _plView.nameLab.text = @"频率";
    _plView.mesLab.text = @"50";
    
    
    [_mkView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.left.equalTo(_xjsjView);
        make.top.equalTo(_sssjView);
    }];
    _mkView.nameLab.text = @"脉宽";
    _mkView.mesLab.text = @"150";
    _mkView.dwLab.text = @" μs";
    
    
    [_sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(80 * IPADSCALE));
        make.height.equalTo(@(30 * IPADSCALE));
        make.bottom.equalTo(_whiteView.mas_bottom).offset(-15 *IPADSCALE);
        make.centerX.equalTo(_whiteView.mas_centerX);
    }];
    _sureBtn.clipsToBounds = YES;
    _sureBtn.layer.cornerRadius = 15 *IPADSCALE;
    [_sureBtn setBackgroundColor:RGBColor(13, 157, 219)];
    [_sureBtn setTitle:@"确认" forState:0];
    [_sureBtn setTitleColor:[UIColor whiteColor] forState:0];
    _sureBtn.titleLabel.font = ZYQFONT(20);
    [_sureBtn addTarget:self action:@selector(sureBtnAction) forControlEvents:UIControlEventTouchUpInside];
    
    
}

- (void)sureBtnAction {
    if (_sureActionMiddleDone) {
        _sureActionMiddleDone(self,0,@"");
        [self hidden];
        [self removeFromSuperview];

    }
}

- (void)hidden {
    if (self) {
        [UIView animateWithDuration:0.2 animations:^{
        self.frame = CGRectMake(0, 0, 0, 0);
            self.hidden = YES;
        } completion:^(BOOL finished) {
            
        }];
        return;
        
        
        [UIView animateWithDuration:0.2 animations:^{
        self.frame = CGRectMake(0, 0, ZYQWIDTH, [UIApplication sharedApplication].keyWindow.frame.size.height);
            self.hidden = NO;
        } completion:^(BOOL finished) {
            
        }];
    }
}

- (void)cfOrSjjrbtnAction:(UIButton *)btn {
    _cfBtn.selected = 0;
    _sjjrBtn.selected = 0;
    btn.selected = YES;
    if(btn == _sjjrBtn) {
        [_sjjrBtn setBackgroundColor:RGBColor(13, 157, 219)];
        [_cfBtn setBackgroundColor:[UIColor whiteColor]];

    }else{
        [_cfBtn setBackgroundColor:RGBColor(13, 157, 219)];
        [_sjjrBtn setBackgroundColor:[UIColor whiteColor]];

    }
}

- (void)initViews {
    _whiteView = [UIView new];
    _tipsLab = [UILabel new];
    _sjjrBtn = [UIButton new];
    _cfBtn = [UIButton new];
    
    [self addSubview:_whiteView];
    [_whiteView addSubview:_tipsLab];
    [_whiteView addSubview:_sjjrBtn];
    [_whiteView addSubview:_cfBtn];
    
    
    _zlsjView = [Chufang_CardView new];
    _cxsjView = [Chufang_CardView new];
    _jgsjView = [Chufang_CardView new];
    _sssjView = [Chufang_CardView new];
    [_whiteView addSubview:_zlsjView];
    [_whiteView addSubview:_cxsjView];
    [_whiteView addSubview:_jgsjView];
    [_whiteView addSubview:_sssjView];

    
    _xjsjView = [Chufang_CardView new];
    _ycsjView = [Chufang_CardView new];
    _plView = [Chufang_CardView new];
    _mkView = [Chufang_CardView new];
    [_whiteView addSubview:_xjsjView];
    [_whiteView addSubview:_ycsjView];
    [_whiteView addSubview:_plView];
    [_whiteView addSubview:_mkView];
    
    
    _sureBtn = [UIButton new];
    [_whiteView addSubview:_sureBtn];

}


- (void)sureBtnwithDoneBlock:(Pac_GetLocalCfView_SureAction)doneBlock CancelBlock:(Pac_GetLocalCfView_CancleAction)cancelBlockOrNil {
    _sureActionMiddleDone = doneBlock;
    _cancleActionMiddleDone = cancelBlockOrNil;
}


@end
